<#include '/admin/header.html' >
<style>
  .layui-input{
  width:75%
  }
 
</style>
<div class="main">
    <!--表单区域  -->
	<form id="addAdminForm" class="layui-form layui-form-pane" action="" enctype="multipart/form-data" style="padding-top:10px;margin-left:10px;">
  		<div class="layui-form-item">
    		<label class="layui-form-label">用户名：</label>
    		<div class="layui-input-block">
      			<input type="text" name="username"  maxlength="12" lay-verify="username" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">密码：</label>
    		<div class="layui-input-block">
      			<input type="password" name="password" id="pwd" maxlength="20" lay-verify="required" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">确认密码：</label>
    		<div class="layui-input-block">
      			<input type="password" type="password" id="regPwd"  fun='checkpwd' maxlength="20" lay-verify="regPwd" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">类型：</label>
    		<div class="layui-input-block">
      			<input type="radio" name="founder" value="0" id="notSuperChk" lay-filter="founder" checked="checked" title="普通管理员">
      			<input type="radio" name="founder" value="1" id="superChk" lay-filter="founder" title="超级管理员">
    		</div>
  		</div>
  		
  		<div class="layui-form-item" id="roletr">
    		<label class="layui-form-label">角色：</label>
    		<div class="layui-input-block">
      			<ul style="width:100%;margin-left:10px;" id="rolesbox">
					<#list roleList as role>
					<li style="width:40%;display:block">
						<input autocomplete="off" type="checkbox" name="roleids" value="${role.roleid }"  />
						${role.rolename }&nbsp;
					</li>
					</#list>
				</ul>
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">状态：</label>
    		<div class="layui-input-block">
      			<input type="radio" name="state" value="1" checked="checked" title="启用">
      			<input type="radio" name="state" value="0"  title="禁用">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">姓名：</label>
    		<div class="layui-input-block">
      			<input type="text" name="realname"  maxlength="12" lay-verify="required"  autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">编号：</label>
    		<div class="layui-input-block">
      			<input type="text" name="userno"  onkeyup='this.value=this.value.replace(/\D/gi,"")' maxlength="32"  autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">部门：</label>
    		<div class="layui-input-block">
      			<input type="text" name="userdept"  maxlength="32"  autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">备注：</label>
    		<div class="layui-input-block">
      			<input type="text" name="remark" maxlength="200" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;margin-left:-7px;;z-index:1000;left: 1px;width: 97%;height: 40px; background:rgba(230,230,230,0.8)"> 
  			<a style="margin: 0px" class="layui-layer-btn0" type="submit" lay-submit="" lay-filter="save_user_admin">保存</a>
  			
  		</div>
  	</form>
</div>
<script>
var index = parent.layer.getFrameIndex(window.name);


layui.use(['form', 'layedit', 'laydate'], function(){
	var form = layui.form(),
    layedit = layui.layedit,
    laydate = layui.laydate;
	form.render(); 
    form.on('radio(founder)', function(data){
    	  if(data.value==1){
    		  $("#roletr").hide();
    	  }else {
    		  $("#roletr").show();
			}
    	});  

    
   /*  密码验证 */
  form.verify({
	  username: function(value, item){ //value：表单的值、item：表单的DOM对象
		    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
		      return '用户名不能有特殊字符';
		    }
		    if(/(^\_)|(\__)|(\_+$)/.test(value)){
		      return '用户名首尾不能出现下划线\'_\'';
		    }
		    if(/^\d+\d+\d$/.test(value)){
		      return '用户名不能全为数字';
		    }
		  },
	  regPwd:function(value) {
   			  var pwd=$("#pwd").val();
   			  if(!new RegExp(pwd).test(value)){
   				 return '两次密码输入不一致';
   			  }
   		  }
     
   		   
   }); 
   
    form.on('submit(save_user_admin)', function(data){
    	var options = {
   			url:ctx+"/core/admin/userAdmin/add-save.do",
   			type:"post",
   			dataType:"json",
   			success:function(data){
   				if(data.result==1){	
   					parent.$.Loading.success(data.message);
   					parent.layer.close(index); //再执行关闭        
   					parent.table.ajax.url(ctx+"/core/admin/userAdmin/list-json.do").load();
   				}else{
   					parent.$.Loading.error(data.message);
   				}
   			}
   		};
   		$("#addAdminForm").ajaxSubmit(options);
       return false;
    });
    
 
   
    
});
</script>
